import { Module } from '@nestjs/common'
import { ConfigModule, ConfigService } from '@nestjs/config'
import { JwtModule as NestJwtModel } from '@nestjs/jwt'
import * as process from 'node:process'

@Module({
  imports: [
    ConfigModule,
    ConfigModule.forRoot({
      isGlobal: true,
      envFilePath: ['.env'],
    }),
    NestJwtModel.registerAsync({
      imports: [ConfigModule],
      useFactory: (configService: ConfigService) => {
        return {
          secret: configService.get(process.env.JWT_SECRET),
          signOptions: { expiresIn: process.env.JWT_EXPIRES_IN },
        }
      },
      inject: [ConfigService],
    }),
  ],
})
export class JwtModule {
}
